<?php
if(isset($_GET['j']) && $_GET['j']!="") {
	$j = $_GET['j'];
	$kd_jaksa = $j;
	$dt_jaksa = mysql_fetch_array(mysql_query("
	SELECT * FROM t_p16_jaksa a
	LEFT JOIN t_pegawai b ON a.kd_pegawai = b.kd_pegawai
	LEFT JOIN r_pangkat c ON b.kd_pangkat = c.kd_pangkat
	WHERE kd_perkara ='".KD_PERKARA."' AND a.kd_pegawai ='".$_GET['j']."'
	"));
} else {
	$j = "";
	$dt_jaksa = mysql_fetch_array(mysql_query("
	SELECT * FROM t_p16_jaksa a
	LEFT JOIN t_pegawai b ON a.kd_pegawai = b.kd_pegawai
	LEFT JOIN r_pangkat c ON b.kd_pangkat = c.kd_pangkat
	WHERE kd_perkara ='".KD_PERKARA."'
	"));
	$kd_jaksa = $dt_jaksa['kd_pegawai'];
}

$dt 		= mysql_fetch_array(mysql_query("SELECT * FROM t_p16a WHERE kd_perkara='".KD_PERKARA."'"));

$tambah = false;

$jaksa_ada = data_tersedia('t_p16_jaksa',KD_PERKARA);
$jaksa_terpakai = mysql_fetch_array(mysql_query("
	SELECT GROUP_CONCAT(kd_pegawai) 
	FROM t_p16_jaksa WHERE kd_perkara ='".KD_PERKARA."'"));

if($jaksa_terpakai[0]!="") {
	$tx_batas ="AND kd_pegawai NOT IN (".$jaksa_terpakai[0].")";
} else {
	$tx_batas ="";
}

if($jaksa_ada && $j!="tambah") {
	$jaksa = $dt_jaksa['kd_pegawai'];
	$nama = $dt_jaksa['nm_lengkap'];
	$pangkat = $dt_jaksa['nm_pangkat'];
	$nip = $dt_jaksa['nip'];
	$jabatan = "JAKSA PENUNTUT UMUM";
} elseif(!$jaksa_ada || $j=="tambah") {
	$nama = "";
	$pangkat = "";
	$nip = "";
	$jabatan = "";
}

$q_jaksa = mysql_query("
	SELECT * FROM t_p16_jaksa a
	LEFT JOIN t_pegawai b ON a.kd_pegawai = b.kd_pegawai
	LEFT JOIN r_pangkat c ON b.kd_pangkat = c.kd_pangkat
	WHERE kd_perkara ='".KD_PERKARA."'
");


?>

<form id="da-form-p16a" class="da-form" method="post" action="modul/perkara/detail.proses.php">
	<div class="da-form-inline">
		<div class="da-form-row">
			<label class="da-form-label">Nomor Surat</label>
			<div class="da-form-item">
			<?php
				if(data_tersedia('t_p16a',KD_PERKARA)) {
					if(LEVEL=="superadmin" || LEVEL=="admin") {
						echo '<input type="text" name="no_surat" placeholder="Contoh:0019/0.5.10.3/Euh.1/09/2013" value="'.$dt['no_surat'].'/0.5.10.3/'.$dt_spdp['jns_pidana'].konversi_tanggal('/m/Y',$dt['tgl_dikeluarkan']).'">';
					} else {
						echo 'PRINT- '.$dt['no_surat'].'/0.5.10.3/'.$dt_spdp['jns_pidana'].konversi_tanggal('/m/Y',$dt['tgl_dikeluarkan']);
					}
				} else {
					$tambah 	= true;
					if(LEVEL=="superadmin" || LEVEL=="admin") {
						echo '<input type="text" name="no_surat" placeholder="Contoh:0019/0.5.10.3/Euh.1/09/2013">';
					} else {
						echo 'PRINT- '.p16a_register($dt_spdp['kd_pidana']).'/0.5.10.3/'.$dt_spdp['jns_pidana'].date('/m/Y');
			?>
						<input type="hidden" name="no_surat" value="<?php echo p16a_register($dt_spdp['kd_pidana']) ?>" />
			<?php
					}
				} 
			?>
			<?php 
				/*$no_surat_print = '';
				$no_surat = '';
				if(data_tersedia('t_p16a',KD_PERKARA)) {
					$no_surat 	= $dt['no_surat'];
					$no_surat_print = 'PRINT- '.$no_surat.'/0.5.10.3/'.$dt_spdp['jns_pidana'].konversi_tanggal('/m/Y',$dt['tgl_dikeluarkan']);
					
				} else {
					$tambah 	= true;
					$no_surat 	= p16a_register($dt_spdp['kd_pidana']);
					$no_surat_print = 'PRINT- '.$no_surat.'/0.5.10.3/'.$dt_spdp['jns_pidana'].date('/m/Y');
				} 
				echo $no_surat_print;*/
				?>
				<!--input type="hidden" name="no_surat" value="<php echo $no_surat >" /-->
			</div>
		</div>
		
		<div class="da-form-row">
			<label class="da-form-label">Tanggal Dikeluarkan</label>
			<div class="da-form-item">
				<input 
					id="da-tgl-p16a-dikeluarkan" 
					type="text" 
					placeholder="Tanggal Dikeluarkan" 
					name="tgl_dikeluarkan" 
					value="<?php echo isset($dt['tgl_dikeluarkan']) ? konversi_tanggal('d-m-Y',$dt['tgl_dikeluarkan']) : '' ?>">
			</div>
		</div>

		<div class="da-form-row">
			<label class="da-form-label">Tempat Dikeluarkan</label>
			<div class="da-form-item">
				<input 
					type="text" 
					name="tmp_dikeluarkan"  
					placeholder="Tempat Dikeluarkan"  
					value="<?php echo $dt['tmp_dikeluarkan'] ?>">
			</div>
		</div>
		
		<fieldset class="da-form-inline">
			<legend>Jaksa Penuntut Umum</legend>
		</fieldset>

		<table class="da-table da-detail-view no-border">
			<tbody>
			<tr>
				<th colspan=2>
				<?php if($jaksa_ada) { ?>
					<div class="btn-toolbar">
						<div class="btn-group">
							<?php 						
								$i = 1;
								while($dt=mysql_fetch_array($q_jaksa)) { 
									if($i==1) {$d=  true;} else {$d = "";}
							?>
								<a <?php tab_aktif($j,$dt['kd_pegawai'],PAGE_ID.'&p2=p16a&j='.$dt['kd_pegawai'],$d)?>>Jaksa <?php echo $i ?></a>
							<?php 
								$i++; } 
				
								if($t!="tambah") { 
								if(LEVEL=="superadmin" || LEVEL=="kasipidum") {
			
							?>
								<a href="?kd=<?php echo KD_PERKARA?>&p2=p16a&j=tambah" class="btn"><i class="icol-add"></i> Tambah</a>
							<?php }} ?>
						</div>
					</div>	
				<?php } ?>
				</th>
			</tr>	
			<tr>
				<th>Nama Lengkap</th>
				<td>
					<?php if(LEVEL!="superadmin" && LEVEL!="kasipidum") { echo $nama; } 
						else { ?>				
				
					<select class="select2 span6" name="kd_jaksa">
					<?php if($jaksa_ada && $j!="tambah") { ?>
						<option value="<?php echo $jaksa ?>"><?php echo $nama ?></option>
					<?php
						}
						$q = mysql_query("SELECT * FROM t_pegawai WHERE nip!='' $tx_batas");
						while($dt = mysql_fetch_array($q)) {
					?>
						<option value="<?php echo $dt['kd_pegawai'] ?>"><?php echo $dt['nm_lengkap'] ?></option>
					<?php } }?>
					</select>
				</td>
			</tr>
			<tr>
				<th>Pangkat</th>
				<td><?php echo $pangkat ?></td>
			</tr>
			<tr>
				<th>NIP</th>
				<td><?php echo $nip ?></td>
			</tr>
			<tr>
				<th>Jabatan</th>
				<td><?php echo $jabatan ?></td>
			</tr>
			</tbody>
		</table>
		<?php if(LEVEL=="superadmin" || LEVEL=="kasipidum") { ?>
			<div class="da-panel-toolbar">
				<div class="btn-toolbar">
					<div class="btn-group">
					<?php if(($jaksa_ada && $j=="") || ($j!="" && $j!="tambah")) { ?>
						<button  id="ubah-jaksa" class="btn cancel"><i class="icol-disk"></i> Ubah</button>
						<a href="detail.proses.php?kd=<?php echo KD_PERKARA?>&jaksa=<?php echo $kd_jaksa ?>" class="btn">
						<i class="icol-cross"></i> Hapus
						</a>
					<?php } else { ?>
						<button  id="tambah-jaksa" class="btn cancel"><i class="icol-disk"></i> Simpan</button>
					<?php } ?>
					</div>
				</div>
			</div>	
		<?php } ?>
	</div>
	<div class="btn-row">
		<!--button class="btn"><i class="icol-calendar-2"></i> Riwayat Dokumen</button-->
		<?php if(!$tambah) { ?>
			<a href="#" id="p16a-dialog" class="btn"><i class="icol-printer"></i> Cetak</a>
		<?php } else { ?>
			<a href="#" class="btn disabled"><i class="icol-printer"></i> Cetak</a>
		<?php } 
			if($tambah){
				if(LEVEL=="superadmin" || LEVEL=="admin" || LEVEL=="kasipidum") {
			?>
			<button id="tambah-p16a" class="btn"><i class="icol-disk"></i> Simpan</button>
		<?php 
				}
			}else{
			
					if(LEVEL=="superadmin" || LEVEL=="admin" || LEVEL=="kasipidum") { ?>
		
						<button id="ubah-p16a" class="btn"><i class="icol-disk"></i> Simpan</button>
		<?php 		}
				}?>
		<input id="mode-input" type="hidden" name="p16a" value="tambah" />
		
		<input type="hidden" name="p16a_jaksa" value="a" />
		<input type="hidden" name="kd" value="<?php echo KD_PERKARA ?>" />
		<input type="hidden" name="kd_jaksa_2" value="<?php echo $kd_jaksa ?>" />
	</div>
</form>

<div id="p16a-dialog-div" style="display:none;">
	<p id="berkas"></p>
</div>
